package com.eoner.managerlibrary.system.request;

import com.eoner.baselib.container.CommonBaseResponse;
import com.eoner.baselib.utils.sp.SPUtils;
import com.eoner.baselibrary.utils.CookieNewUtil;
import com.eoner.baselibrary.utils.Utils;
import com.eoner.common.config.Config;
import com.eoner.commonbean.config.SysConfigBean;
import com.eoner.commonbean.config.SystemConfigBean;
import com.eoner.managerlibrary.system.callback.SystemConfigCallBack;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MultipartBody;

public class SystemConfigRequest {

    /**
     * 更新信息
     * @param callBack
     */
    public void requestSystemConfig(final SystemConfigCallBack callBack){
        MultipartBody.Builder builder = new MultipartBody.Builder()
                .setType(MultipartBody.FORM);//表单类型

        builder.addFormDataPart("app_version", CookieNewUtil.getVersionName(Utils.getContext()));
        builder.addFormDataPart("platform","android");
        builder.addFormDataPart("token", SPUtils.getInstance().getString(Config.CUSTOMER_TOKEN));
        SystemConfigRetrofit.getInstance().requestSysConfig(builder.build().parts()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<CommonBaseResponse<SysConfigBean>>() {

            @Override
            public void onSubscribe(@io.reactivex.annotations.NonNull Disposable d) {

            }

            @Override
            public void onNext(@io.reactivex.annotations.NonNull CommonBaseResponse<SysConfigBean> bean) {
                if(0 == bean.getCode()){
                    callBack.onSuccess(bean.data);
                } else {
                    callBack.onFailed("");
                }
            }

            @Override
            public void onError(@io.reactivex.annotations.NonNull Throwable e) {
                callBack.onFailed(e.toString());
                e.printStackTrace();
            }

            @Override
            public void onComplete() {

            }
        });
    }

    /**
     * 公共配置信息
     * @param callBack
     */
    public void requestSysConfig(final SystemConfigCallBack callBack){

    }
}
